<template>
	<view>
		<view v-if="types==0">
			<!-- <uni-search-bar :radius="100" @confirm="indexSearch" placeholder="搜索" bgColor="#000"></uni-search-bar> -->
			<uni-search-bar  @confirm="search" @change="search" placeholder="搜索" bgColor="#000" :radius="100" v-model="name"></uni-search-bar>
			<view class="content chaxun">
				<view class="cre-lei">
					<view class="zuinquire">
						<picker mode="selector" :range="status" range-key="name" @change="statusChange" >
							<view class="zstate">组织状态</view>
						</picker>
						<image src="../../static/xialajiantoublack.png" class="xialajiantoublack"></image>
					</view>
					<view class="zuinquire">
						<picker mode="selector" :range="type" range-key="name" @change="typeChange" >
							<view class="zstate">组织类型</view>
						</picker>
						<image src="../../static/xialajiantoublack.png" class="xialajiantoublack"></image>
					</view>
					<view class="zuinquire">
						<picker mode="selector" :range="year" range-key="name" @change="yearChange" >
							<view class="zstate">年检时间</view>
						</picker>
						<image src="../../static/xialajiantoublack.png" class="xialajiantoublack"></image>
					</view>
					<view class="zuinquire">
						<picker mode="selector" :range="yearStatus" range-key="name" @change="yearStatusChange" >
							<view class="zstate">年检结果</view>
						</picker>
						<image src="../../static/xialajiantoublack.png" class="xialajiantoublack"></image>
					</view>
				</view>
				<view class="cmon" v-for="(item, index) in bgData" :key="index" @click="tozhuXiangqing(item.id)">
					<view class="catering">
						<text class="caorg">{{item.name}}</text>
						<text class="crd">{{item.status}}</text>
					</view>
					<view class="team">
						<image src="../../static/teams.png" mode="" class="peop"></image>
						<text class="sheteam">{{item.society_type}}</text>
						<text class="dengtime">登记日期：{{item.reg_time}}</text>
					</view>
				</view>
				<uni-load-more v-if="showloading" :status="more"></uni-load-more>
				<!--餐饮管理组织-->
			</view>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
	export default {
		components: {
			uniSearchBar,
			uniLoadMore
		},
		data() {
			// const currentDate = this.getDate({
			// 	format: true
			// })
			return {
				status:['黑名单','白名单'],
				type:[],
				year:[],
				statusValue:'',
				yearStatus:['不合格','合格'],
				typeValue:'',
				yearValue:'',
				yearStatusValue:'',
				hasData: true, //是否还有数据
				bgData: [],
				page: 1,
				more: 'loading',
				showloading: false, //是否显示loading
				types:'',
				name:""
				// indexSearch:""
			}
		},
		onShow() {
			console.log('credit');
		},
		onLoad(res) {
			this.getSociety()
			this.getType()
			this.types=uni.getStorageSync('types')
		},
		onReachBottom() {
			if (this.hasData) {
				this.page++
				this.showloading = true
				// this.getSociety()
				this.getbot()
			}
		},
		methods: {
			// 搜索框
			search(){
				let _this=this
				let id = _this.id
				// console.log(_this.$data.name.value)
				// return false
				this.$post('v1/society/society',{name:_this.$data.name.value,page:1})
				.then(function(res){
					console.log(res)
					_this.bgData =res.data.data.info;
				})
			},
			
			statusChange(e){
				console.log(e)
				 let index=e.detail.value
				this.statusValue=index
				this.getSociety({status:e.detail.value})
			},
			typeChange(e){
				let index=e.detail.value
				this.typeValue=index
				this.getSociety({page:1,type:e.detail.value,status:this.statusValue})
			},
			yearChange(e){
				let index=e.detail.value
				this.yearValue=index
				this.getSociety({year:e.detail.value,status:this.statusValue,type:this.typeValue})
			},
			yearStatusChange(e){
				let index=e.detail.value
				this.yearStatusValue=index
				this.getSociety({yearStatus:e.detail.value,status:this.statusValue,type:this.typeValue,year:this.yearValue})
			},
			tozhuXiangqing(id) {
				uni.navigateTo({
					url: './creditDetail/creditDetail?id='+id
				})
			},
			toArray(data,obj={},arr=[]){
				for(let i in data){
					obj={}
					obj.id=i
					obj.name = data[i]
					arr.push(obj)
				}
				return arr
			},
			getType(){
				let type = this.typeValue
				let year = this.yearValue
				this.$get('v1/society/get-type')
				.then(res=>{
					console.log(res)
					this.type=this.toArray(res.data.type) 
					this.year=res.data.year
				})
			},
			getbot(){
				console.log(123)
				let e={};
				e.page = this.page;
				e.status = this.statusValue;
				e.yearStatus = this.yearStatusValue;
				e.year = this.yearValue;
				e.type = this.typeValue;
				console.log(e)
				//return false;
				this.$post('v1/society/society',e)
					.then(res => {
						console.log(res.data.data.info)
						if (res.data.code == 200) {
							// this.yearStatus=this.toArray(res.data.yearStatus) 
							// this.type=this.toArray()
							
							if (res.data.data.info.length) {
								this.hasData = true
								
								// this.bgData =this.bgData.concat(res.data.data.info)
								this.bgData =res.data.data.info
								//this.bgData =this.bgData.push(res.data.data.info)
								//console.log(this.bgData)
								// this.bgData=res
							} else {
								// this.bgData =res.data.data.info
								this.hasData = false
							}
							this.showloading = false
						}
					})
					.catch(error => {
						console.log(error);
						this.showloading = false
					})
			},
			getSociety(e) {
				if(e){
					
				}else{
					e={}
				}
				e.page=this.page
				console.log(e)
				// let yearStatus = this.yearStatusValue
				this.$post('v1/society/society',e)
					.then(res => {
						console.log(res.data.data.info)
						if (res.data.code == 200) {
							// this.yearStatus=this.toArray(res.data.yearStatus) 
							// this.type=this.toArray()
							if (res.data.data.info.length) {
								this.hasData = true
								// this.bgData =this.bgData.concat(res.data.data.info)
								this.bgData =res.data.data.info
								// this.bgData=res
							} else {
								this.hasData = false
							}
							this.showloading = false
						}
					})
					.catch(error => {
						console.log(error);
						this.showloading = false
					})
			}
		}
	}
</script>

<style>
	.xialajiantoublack {
		width: 20rpx;
		height: 15rpx;
		position: absolute;
		top: 17rpx;
		right:20rpx;
	}

	.chaxun {
		padding: 20rpx 0;
	}

	.cre-lei {
		display: flex;
		padding: 20rpx 10rpx 20rpx 25rpx;
		border-bottom: 1rpx solid #EAEAEA;
	}

	.zuinquire {
		width: 25%;
		text-align: center;
		display: flex;
		position: relative;
		/* margin-left: 25rpx; */
	}

	.zstate {
		font-weight: 600;
		font-size: 26rpx
	}

	.caorg {
		font-size: 26rpx;
		font-weight: 600;
		color: #333;
	}

	.crd {
		font-size: 24rpx;
		color: #8BC34A;
		float: right;
	}

	.sheteam {
		font-size: 24rpx;

	}

	.dengtime {
		float: right;
		color: #999;
		font-size: 24rpx;
		/* font-weight: 600; */
	}

	.team,
	.catering {
		overflow: hidden;
		line-height: 50rpx;
	}

	.peop {
		width: 26rpx;
		height: 22rpx;
		margin: 0 15rpx;
		vertical-align: middle;
	}

	.cmon {
		padding: 10rpx 30rpx;
		border-top: 2rpx solid #EAEAEA;
	}
</style>
